package cn.oms.auth.provider.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
public class TokenConfig {

    // 定义JWT令牌的解密口令
    private final String SINGING_KEY="allenchen-OMS";

    // 向Spring 容器中注入一个令牌生成器对象
    @Bean
    public TokenStore tokenStore(){
        return new JwtTokenStore(accessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter accessTokenConverter(){
        // 实例化Jwt加密器
        JwtAccessTokenConverter converter=
                new JwtAccessTokenConverter();
        //  设置加密解密口令
        converter.setSigningKey(SINGING_KEY);
        return converter;
    }
}
